/**
 * Created by Administrator on 2016/7/13.
 */
    angular.module('app', ['app.controllers', 'app.services', 'ui.router', 'flow', 'ui.bootstrap', 'frapontillo.bootstrap-switch'])

        .config(function($stateProvider, $httpProvider, $urlRouterProvider){
            //post方式传送的是json形式的数据
            $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
            var param = function (obj) {
                var query = '', name, value, fullSubName, subName, subValue, innerObj, i;

                for (name in obj) {
                    value = obj[name];
                    //instanceof 运算符1.判断一个实例是否属于某种类型
                    //                 2.可以在继承关系中用来判断一个实例是否属于它的父类型
                    if (value instanceof Array) {
                        for (i = 0; i < value.length; ++i) {
                            subValue = value[i];
                            fullSubName = name + '[' + i + ']';
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    }
                    else if (value instanceof Object) {
                        for (subName in value) {
                            subValue = value[subName];
                            fullSubName = name + '[' + subName + ']';
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    }
                    else if (value !== undefined && value !== null)
                        query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                }

                return query.length ? query.substr(0, query.length - 1) : query;
            };
            localStorage.ipAddress = 'http://192.168.30.150:5007';
            //  localStorage.ipAddress = 'http://192.168.30.156:5007';
            localStorage.userPageNum = 1;
            localStorage.tenderPageNum = 1;
            localStorage.biddingPageNum = 1;
            localStorage.tenderNewsPageNum = 1;
            localStorage.companysPageNum = 1;
            localStorage.tenderDatabasePageNum = 1;
            localStorage.tenderDatabaseDetailPageNum = 1;
            localStorage.projectDatabasePageNum = 1;


            // localStorage.ipAddress = 'http://121.41.56.218:5005';
            if(undefined==localStorage.tokenID){
                localStorage.tokenID = '-1';
            }
            if(undefined==localStorage.titleName) {
                localStorage.titleName = '登陆';
            }
            $httpProvider.defaults.transformRequest = [function (data) {
                return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
            }];

            $stateProvider
                //登录
                .state('login', {
                    url : '/login',
                    templateUrl : 'login.html'
                })
                //用户管理
                .state('usermanager', {
                    url : '/usermanager',
                    templateUrl : 'templates/userManager.html'
                })
                //招标信息
                .state('tenderlist', {
                    url : '/tenderlist',
                    templateUrl : 'templates/tenderList.html'
                })
                //招标信息详情界面
                .state('tenderdetail', {
                    url : '/tenderdetail/:tenderID',
                    templateUrl : 'templates/tenderDetail.html'
                })
                //中标信息
                .state('winbiddinglist',{
                    url : '/winbiddinglist',
                    templateUrl : 'templates/winbiddingList.html'
                })
                //中标信息详情界面
                .state('winbiddingdetail', {
                    url : '/winbiddingdetail/:biddingID',
                    templateUrl : 'templates/winbiddingDetail.html'
                })
                //招标资讯
                .state('tendernews', {
                    url : '/tendernews',
                    templateUrl : 'templates/tenderNews.html'
                })
                //招标资讯详情
                .state('tendernewsdetail', {
                    url : '/tendernewsdetail/:newsID',
                    templateUrl : 'templates/tenderNewsDetail.html'
                })
                //创建招标资讯
                .state('createnews', {
                    url : '/createnews',
                    templateUrl : 'templates/createNews.html'
                })
                //企业数据库
                .state('companys', {
                    url : '/companys',
                    templateUrl : 'templates/companys.html'
                })
                //企业数据库详情界面
                .state('companydetail', {
                    url : '/companydetail/:companyID',
                    templateUrl : 'templates/companyDetail.html'
                })
                //企业数据库详情内查看图片界面
                .state('companyimg', {
                    url : '/companyimg/:tag/:companyID',
                    templateUrl : 'templates/companyImg.html'
                })
                //投标数据库
                .state('tenderdatabase', {
                    url : '/tenderdatabase',
                    templateUrl : 'templates/tenderDatabase.html'
                })
                //投标数据库详情页面
                .state('tenderdatabasedetail', {
                    url : '/tenderdatabasedetail/:companyID',
                    templateUrl : 'templates/tenderDatabaseDetail.html'
                })
                //项目数据库
                .state('projectdatabase', {
                    url : '/projectdatabase',
                    templateUrl : 'templates/projectDatabase.html'
                })
                //项目数据库详情页面
                .state('projectdatabasedetail', {
                    url : '/projectdatabasedetail/:projectID',
                    templateUrl : 'templates/projectDatabaseDetail.html'
                })
                //会员充值活动
                .state('members', {
                    url : '/members',
                    templateUrl : 'templates/members.html'
                })
            ;

            $urlRouterProvider.otherwise("login");
        })
        .factory('Data',function(){
            return{
                operationList:[
                    {
                        id : 1,
                        name : "用户管理",
                        url : "#/usermanager"
                    },
                    {
                        id : 2,
                        name : "招标信息",
                        url : "#/tenderlist"
                    },
                    {
                        id : 3,
                        name : "中标公告",
                        url : "#/winbiddinglist"
                    },
                    {
                        id : 4,
                        name : "招标资讯",
                        url : "#/tendernews"
                    },
                    {
                        id : 5,
                        name : "企业数据库",
                        url : "#/companys"
                    },
                    {
                        id : 6,
                        name : "投标数据库",
                        url : "#/tenderdatabase"
                    },
                    {
                        id : 7,
                        name : "项目数据库",
                        url : "#/projectdatabase"
                    },
                    {
                        id : 8,
                        name : "会员充值活动",
                        url : "#/members"
                    }
                ]
            }
        });
